package com.leetcode.LC;

public class LC665 {
    public boolean checkPossibility(int[] nums) {

        if (nums.length<3){
            return true;
        }
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
                if (i-1>=0&&i+2<nums.length&&!(((nums[i]>=nums[i-1]&&nums[i]<=nums[i+2])||(nums[i+1]>=nums[i-1]&&nums[i+1]<=nums[i+2])))){
                    return false;
                }
                count++;
                if (count > 1) {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new LC665().checkPossibility(new int[]{2,7,1}));//3423两个三之间的两个数必须有一个大于等于前面的三小于等于后面的三
    }
}
